package com.xiaoxi.mementomode;

import com.xiaoxi.mementomode.game.Gamer;
import com.xiaoxi.mementomode.memento.Memento;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.mementomode
 * @ClassName Main
 * @Description TODO
 * @Date 2023/3/27 20:23
 * @Version 1.0
 */
public class Main {
    public static void main(String[] args) {
        Gamer gamer = new Gamer(1000);
        Memento memento = gamer.createMemento(); // 保存最初状态
        int i = 0;
        while (++i < 100) {
            System.out.println("=================");
            System.out.println("当前状态：" + gamer);

            gamer.bet();

            System.out.println("所持有的金币：" + gamer.getMoney());
            if (gamer.getMoney() > memento.getMoney()) {
                System.out.println("金币看上去很多，保存该版本");
                memento = gamer.createMemento();
            } else if (gamer.getMoney() < memento.getMoney() / 2) {
                System.out.println("金币太少了，回到上一个版本");
                gamer.restoreMemento(memento);
                System.out.println("上一个版本状态：" + gamer.getMoney() + " " + gamer.getFruits());
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("最后金币：" + gamer.getMoney());
        System.out.println("最后水果：" + gamer.getFruits());
    }
}
